//
//  ConsultHistoryCtr.swift
//  smosky
//
//  Created by zhuxietong on 2018/8/8.
//  Copyright © 2018年 tianrun. All rights reserved.
//

import Foundation
import soapp
import Eelay
import AsyncDisplayKit

class ConsultHistoryCtr:ASListController{
    
    var sections:TP.section{
        get{
            let sec:TP.section = [
                [
//                    [
//                        "title":"买家已发起申请",
//                        "message":"发起了退货退款申请，货物状态:未发货，原因：拍多/拍错/不想要，金额：145元。",
//                        "time":"2018-03-16 15:39",
//                        "cellID":"me",
//                    ],
//                    [
//                        "title":"买家已发起申请",
//                        "message":"发起了退货退款申请，货物状态:未发货，原因：拍多/拍错/不想要，金额：145元。",
//                        "time":"2018-03-16 15:39",
//                        ],
//                    [
//                        "title":"买家已发起申请",
//                        "message":"发起了退货退款申请，货物状态:未发货，原因：拍多/拍错/不想要，金额：145元。",
//                        "time":"2018-03-16 15:39",
//                        ],
//                    [
//                        "title":"买家已发起申请",
//                        "message":"发起了退货退款申请，货物状态:未发货，原因：拍多/拍错/不想要，金额：145元。",
//                        "time":"2018-03-16 15:39",
//                        "cellID":"me",
//                        ],
//                    [
//                        "title":"买家已发起申请",
//                        "message":"发起了退货退款申请，货物状态:未发货，原因：拍多/拍错/不想要，金额：145元。",
//                        "time":"2018-03-16 15:39",
//                        ],
//                    [
//                        "title":"买家已发起申请",
//                        "message":"发起了退货退款申请，货物状态:未发货，原因：拍多/拍错/不想要，金额：145元。",
//                        "time":"2018-03-16 15:39",
//                        "cellID":"me",
//                        ],
//                    [
//                        "title":"买家已发起申请",
//                        "message":"发起了退货退款申请，货物状态:未发货，原因：拍多/拍错/不想要，金额：145元。",
//                        "time":"2018-03-16 15:39",
//                        ],
//                    [
//                        "title":"买家已发起申请",
//                        "message":"发起了退货退款申请，货物状态:未发货，原因：拍多/拍错/不想要，金额：145元。",
//                        "time":"2018-03-16 15:39",
//                        "cellID":"me",
//                        ],
                ]
            ]
            return sec
        }
    }
    
    let selector:TP.selector = [
        "cellID<me>":ChatPopCell.self,
        "<default>":ChatPopCell.self,
    ]
    
    override func viewDidLoad() {
        super.viewDidLoad()
        tableNode.backgroundColor = UIColor.table_bg_color
        load(sections: sections, selector: selector)
        title = "协商历史".loc
        mo_request_send()
    }
    
    var ID:String{
        get{
            return mo.model.possible("__model.id","refundid", default: "")
        }
    }
    
    
    
    override func mo_request_send() {
        
        weak var wself = self
        loadingV.loading()
        JoTask().get.log.params(["refundid":ID])._surl(.售后协商历史).json_handle { (status, msg, obj, resp) in
            wself?.loadingV.dismiss()
            if status.isSuccess{
                if let dict = obj as? NSMutableDictionary{
                    wself?.mo.detail = dict
                    return
                }
            }
            wself?.mo_request_alert(msg: msg, title: "", bt_title: "")
            }.run()
    }
    
    override func mo_detail_reload() {
        tableNode.load(sections: sections, selector: selector)

        let list = DataNode.path(node: "list", mo.detail, value: NSMutableArray())
        list.list { (dict:NSMutableDictionary, i) in
            if dict["msgtype",""] == "1"
            {
                dict["cellID"] = "me"
            }
            else{
                dict["cellID"] = "ta"
            }
        }
        tableNode.model["section0"] = list
        tableNode.reloadData()
        //        let msgid = MsgMap.getMsgID(type: .order, objID: self.orderID)
        
    }
    
    

}
